package controller;

import dao.PatientDao;
import entity.Patient;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import service.PatientService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/Patient")
@Scope("prototype")
public class PatientController {

    @Resource(name = "patientDao")
    private PatientDao patientDao;
    @Resource(name = "patientService")
    private PatientService patientService;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(Patient patient, @RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize,String cFirstDate ,String cLastDate){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("total",patientDao.getCount(patient));
        map.put("rows",patientService.query(patient.getpName(),patient.getpSex(),cFirstDate,cLastDate,pageSize,pageNumber));
        return map;
    }
}
